package values.level
{
import values.events.ItemValueEvent;
import values.events.LevelEvent;

[Event(name="readyToLevelUp", type="values.events.LevelEvent")]
/**
 * CityLevelValue
 * @author jliang
 *
 */
public class CityLevelValue extends DynamicLevelValue
{
	//==========================================================================
	//  Overridden methods: DynamicLevelValue
	//==========================================================================
	override public function get maxLevel():int
	{
		return CityLevelValueList.maxLevel;
	}
	
	override public function getLevelValue(lv:int):LevelValue
	{
		return CityLevelValueList.getByLevel(lv);
	}
	
	override protected function resourceChangedHandler(event:ItemValueEvent):void
	{
		if (resource >= nextResource && !isMaxLevel)
		{			
			this.dispatchEvent(new LevelEvent(LevelEvent.READY_TO_LEVEL_UP, this));
		}
	}
	//==========================================================================
	//  Public methods
	//==========================================================================
	public function levelUp():void
	{
		_level ++;
		updateNextResource();
		this.dispatchEvent(new LevelEvent(LevelEvent.LEVEL_CHANGED, this));
	}
}
}